package cn.xluobo.business.wechat.miniapp.course.controller;

import cn.xluobo.business.sc.course.domain.req.time.ReqSearchClaTime;
import cn.xluobo.business.sc.course.domain.resp.time.RespClaTime;
import cn.xluobo.business.sc.student.domain.req.ReqClaTimeAttend;
import cn.xluobo.business.sc.student.service.BusinessScStudentCourseService;
import cn.xluobo.business.wechat.miniapp.course.domain.resp.RespClaTimeAttendDetail;
import cn.xluobo.business.wechat.miniapp.course.domain.resp.RespClaTimeDetail;
import cn.xluobo.business.wechat.miniapp.course.domain.resp.RespPlanClaTime;
import cn.xluobo.business.wechat.miniapp.course.service.WechatMiniClaTimeService;
import cn.xluobo.core.api.APIResponse;
import cn.xluobo.core.page.RespPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：KingLong
 * @date ：Created in 2020/10/22 12:49
 */
@RestController
@RequestMapping("/api/wechat/miniapp/{appId}/cla/time")
public class WechatMiniClaTimeController {

    @Autowired
    private WechatMiniClaTimeService miniClaTimeService;
    @Autowired
    private BusinessScStudentCourseService businessStudentCourseService;

    /**
     * 今日课程
     * @return
     */
    @GetMapping("/todayCla")
    public APIResponse todayCla() {
        List<RespPlanClaTime> todayClaTimeList = miniClaTimeService.todayCla();
        return APIResponse.toAPIResponse(todayClaTimeList);
    }

    /**
     * 课程列表
     * @param reqSearchClaTime
     * @return
     */
    @GetMapping("/claTimeList")
    public APIResponse claTimeList(ReqSearchClaTime reqSearchClaTime) {
        List<RespPlanClaTime> todayClaTimeList = miniClaTimeService.claTimeList(reqSearchClaTime);
        return APIResponse.toAPIResponse(todayClaTimeList);
    }

    /**
     * 排课详情
     * 用于: 记上课页面 展示信息
     * @param courseTimeId
     * @return
     */
    @GetMapping("/claTimeDetail/{courseTimeId}")
    public APIResponse claTimeDetail(@PathVariable("courseTimeId") Long courseTimeId) {
        RespClaTimeDetail claTimeDetail = miniClaTimeService.claTimeDetail(courseTimeId);
        return APIResponse.toAPIResponse(claTimeDetail);
    }

    /**
     * 记上课
     * @param reqClaTimeAttend
     * @return
     */
    @PostMapping("/claTimeAttend")
    public APIResponse claTimeAttend(@RequestBody ReqClaTimeAttend reqClaTimeAttend) {
        return businessStudentCourseService.claTimeAttend(reqClaTimeAttend);
    }

    /**
     * 已上课 详情
     *
     * 已记录上课 展示上课详情
     * @return
     */
    @GetMapping("/attendDetail/{courseTimeId}")
    public APIResponse attendDetail(@PathVariable("courseTimeId") Long courseTimeId) {
        RespClaTimeAttendDetail attendDetail = miniClaTimeService.attendDetail(courseTimeId);
        return APIResponse.toAPIResponse(attendDetail);
    }

    /**
     * 上课记录
     * 分页查询
     * @param reqSearchClaTime
     * @return
     */
    @GetMapping("/claTimeListForAttend")
    public APIResponse claTimeListForAttend(ReqSearchClaTime reqSearchClaTime) {
        RespPage<RespClaTime> respPage = miniClaTimeService.claTimeListForAttend(reqSearchClaTime);
        return APIResponse.toAPIResponse(respPage);
    }
}
